#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__

#include<iostream>
#include<string>
#include<unistd.h>

//先描述
class Channel
{
public:
    Channel(int wfd, pid_t who)
        : _wfd(wfd)
        , _who(who)
    {
        _name = "Channel-" + std::to_string(wfd) + "-" + std::to_string(who);
    }

    std::string Name()
    {
        return _name;
    }

    pid_t Id()
    {
        return _who;
    }

    int Wfd()
    {
        return _wfd;
    }

    void close()
    {
        ::close(_wfd);
    }

    //派发任务, 向管道中写数据
    void Send(int cmd)
    {
        ::write(_wfd, &cmd, sizeof(cmd));
    }
    ~Channel()
    {}

private:
    int _wfd; //文件描述符
    std::string _name;
    pid_t _who; //进程id
};

#endif